<template>
  <div>
    <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-form">
      <el-row :gutter="24">
        <el-col :span="12" :offset="0">
          <el-form-item label="流水号" prop="serialNumber">
            <el-input v-model="form.serialNumber" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="类别" prop="typeId">
            <el-select v-model="form.typeId" placeholder="请选择">
              <el-option v-for="item in TypeList" :key="item.id" :label="item.typeName" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="付款方" prop="payer">
            <el-input v-model="form.Payee"></el-input>
          </el-form-item>
          <el-form-item label="应付金额" prop="payable">
            <el-input v-model="form.payable"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="付款日" prop="lastPaymentDate">
            <el-date-picker v-model="form.lastPaymentDate" type="datetime" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="收款方" prop="payee">
            <el-input v-model="form.payee"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="form.remarks">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button type="primary" @click="submitForm('form')">编辑应付</el-button>
        <el-button @click="resetForm('form')">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  ReversePaymentapi,
  GetPaytypeapi,
  UpdatePaymentapi,
} from "@/api/FinanceManage/Payments";
export default {
  data() {
    return {
      form: {},
      TypeList: [],
    };
  },
  methods: {
    //反填应收信息
    onReverse() {
      var dto = {
        id: this.$route.query.id,
      };
      ReversePaymentapi(dto).then((res) => {
        this.form = res.data.data;
      });
    },

    //加载支付类别
    onTypeList() {
      GetPaytypeapi().then((res) => {
        this.TypeList = res.data.data;
      });
    },

    //编辑应收信息
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          UpdatePaymentapi(this.form).then(
            (res) => {
              if (res.data.totalCount > 0) {
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              }
              this.$router.push("PaymentShow");
            },
            (err) => {
              this.$message({
                message: "修改失败",
                type: "error",
              });
            }
          );
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$router.push("PaymentShow");
    },
  },
  created() {
    //反填应收信息
    this.onReverse();

    //加载支付类别
    this.onTypeList();
  },
};
</script>

<style></style>